<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 项目详情</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">

    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="row">
        <div class="col-sm-5">
            <div class="wrapper wrapper-content animated fadeInUp">
                <div class="ibox" id="detail-ibox">
                    <div class="ibox-content">
                        <div class="row">
                            <div class="col-sm-12">
                                <div class="m-b-md">
                                    <!-- <a href="project_detail.html#" class="btn btn-white btn-xs pull-right">编辑项目</a> -->
                                    <h2>西安鼎拓</h2>
                                </div>
                                <dl class="dl-horizontal">
                                    <dt>状态：</dt>
                                    <dd><span class="label label-primary" id="status-dd">进行中</span>
                                    </dd>
                                </dl>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-sm-5">
                                <dl class="dl-horizontal">
                                    <dt>负责人：</dt>
                                    <dd>Beaut-zihan</dd>
                                    <dt>版本：</dt>
                                    <dd>v1.4.2</dd>
                                    <dt>任务：</dt>
                                    <dd><button class="btn btn-white btn-sm" onclick="task_list(6)"><i class="fa fa-clock-o"></i>
                                            查看</button></dd>
                                </dl>
                            </div>
                            <div class="col-sm-7" id="cluster_info">
                                <dl class="dl-horizontal">
                                    <dt>创建于：</dt>
                                    <dd id="creat-time-dd">2014年 2月16日 03:01</dd>
                                    <dt>计划结束日期：</dt>
                                    <dd id="plane-time-dd">2014年 11月7日 22:03</dd>
                                    <dt>结束于：</dt>
                                    <dd id="end-time-dd">2014年 2月16日 03:01</dd>
                                </dl>
                            </div>
                        </div>
                        <!-- <div class="row">
                            <div class="col-sm-12">
                                <dl class="dl-horizontal">
                                    <dt>当前进度</dt>
                                    <dd>
                                        <div class="progress progress-striped active m-b-sm">
                                            <div style="width: 0%;" class="progress-bar"></div>
                                        </div>
                                        <small>当前已完成项目总进度的 <strong>0%</strong></small>
                                    </dd>
                                </dl>
                            </div>
                        </div> -->

                    </div>
                </div>
            </div>
        </div>
        <div class="col-sm-4">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>任务列表</h5>
                </div>
                <div class="ibox-content">
                    <ul class="todo-list m-t small-list ui-sortable" id="task-list">
                        <!-- <li>
                            <div class="radio i-checks"> <label> <i></i>
                                test</label><small class="label label-primary"><i class="fa fa-flag"></i> 自己</small>
                                <small class="label "><i class="fa fa-clock-o"></i> 开始2018-45-89</small>
                                <small class="label ">=></small>
                                <small class="label "><i class="fa fa-clock-o"></i> 开始2018-45-89</small>
                                <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"><strong>成员</strong>
                                </button>
                            </div>
                        </li> -->
                    </ul>
                </div>
            </div>
        </div>
        <div class="col-sm-3">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>成员列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="btn-group" style="text-align:center">
                        <button type="button" class="btn btn-white" id="delete-user-btn" onclick="delete_user()">删除成员
                        </button>
                        <button type="button" disable="true" class="btn btn-white" id="add-user-btn" data-toggle="modal"
                            data-target="#addUser" onclick="add_user_init()" disabled>添加成员
                        </button>
                        <button type="button" class="btn btn-white" id="be-leader-btn" onclick="be_leader()">提升职位
                        </button>
                    </div>

                    <ul class="todo-list m-t small-list ui-sortable" id="member-list">
                    </ul>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="addUser" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated bounceInRight">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                            class="sr-only">关闭</span>
                    </button>
                    <i class="fa fa-laptop modal-icon"></i>
                    <h4 class="modal-title">新的成员</h4>
                    <small class="font-bold">召唤新的小伙伴
                </div>
                <div class="modal-body">
                    <div class="form-group"><label>备注:</label> <input type="text" id="usr-remarks-ipt" placeholder="请输入职务描述"
                            class="form-control"></div>
                    <div class="form-group">
                        <label>人员</label>
                        <select class="form-control m-b" name="account" id="user-select">

                        </select>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" onclick="add_user()">保存</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 全局js -->
    <script src="js/jquery.min.js?v=2.1.4"></script>
    <script src="js/bootstrap.min.js?v=3.3.6"></script>

    <!-- iCheck -->
    <script src="js/plugins/iCheck/icheck.min.js"></script>

    <!-- 自定义js -->
    <script src="js/content.js?v=1.0.0"></script>
    <script type="text/javascript" src="js/host.js"></script>

    <script>
        var project_id = null;
        var leader_id = null;
        var task_id = null;
        function get_select_user(leader_pass) {
            var radio = document.getElementsByName("user-rad");
            var selectvalue = null;   //  selectvalue为radio中选中的值
            for (var i = 0; i < radio.length; i++) {
                if (radio[i].checked == true) {
                    selectvalue = radio[i].value;
                    if ((leader_id == selectvalue) && leader_pass) {
                        selectvalue = -1;
                    }
                    break;
                }
            }
            return selectvalue;
        }

        function delete_user(id) {
            var user_id = get_select_user(false)
            if (user_id == null) {
                alert("请选择要删除的人员");
                return;
            } else if (user_id == -1) {
                alert("不能删老大");
                return;
            }
            $.ajax({
                type: "POST",
                url: localhost + "/task/taskMemberUserDel",
                data: '{"user_id":' + user_id + ',"task_id":' + task_id + '}',
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        alert("删除成功");
                        member_list(task_id);
                    } else {
                        alert("删除失败"+ data["response_msg"]);
                    }
                }
            });
        }

        function be_leader() {
            var user_id = get_select_user(true)
            if (user_id == null) {
                alert("请选择要删除的人员");
                return;
            } else if (user_id == -1) {
                alert("想当领导想疯了?");
                return;
            }
            $.ajax({
                type: "POST",
                url: localhost + "/task/taskEditLeader",
                data: '{"task_id":' + task_id + ',"user_id":' + user_id + '}',
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        alert("设置负责人成功");
                        member_list(task_id);
                    } else {
                        alert("设置负责人失败"+ data["response_msg"]);
                    }
                }
            });
        }

        function add_user() {
            if (project_id == null) {
                $('#addUser').modal('hide');
                return;
            }
            var id = $("#user-select").val();
            var remarks = $("#usr-remarks-ipt").val();
            $.ajax({
                type: "POST",
                url: localhost + "/task/taskMemberUserAdd",
                data: '{"session_user_id":' + id + ',"project_id":' + project_id + ',"remarks":"' + remarks + '","task_id":' + task_id + '}',
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        alert("添加成功");
                        member_list(task_id);
                    } else {
                        alert("添加失败"+ data["response_msg"]);
                    }
                    $('#addUser').modal('hide');
                }
            });
        }

        function add_user_init(id) {
            if (project_id == null) {
                // alert("请选中项目");
                $('#addUser').modal('hide');
                return;
            }
            $.ajax({
                type: "POST",
                url: localhost + "/task/taskEmptyPerson",
                data: '{"page":' + 1 + ',"size":5000,"object_id":' + project_id + '}',
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        $('#user-select').empty();
                        var html = '';
                        $.each(data["response_data"]["data"], function (commentIndex, comment) {
                            html += '<option value=' + comment["id"] + '>' + comment["user_name"] + ' </option>'
                        });
                        $('#user-select').html(html);
                    }
                }
            });
        }

        function member_list(id) {
            task_id = id;
            $.ajax({
                type: "POST",
                url: localhost + "/task/taskMemberInfo",
                data: '{"task_id":' + id + '}',
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        $('#member-list').empty();
                        var html = '';
                        $.each(data["response_data"], function (commentIndex, comment) {
                            if (comment["user_name"] == comment["leader"]) {
                                leader_id = comment["id"];
                                html += '<li id="username' + comment["id"] + '"> <div class="radio i-checks"> <label> <input type="radio" name="user-rad" value="' + comment["id"] + '"> <i></i> ' + comment["user_name"] + '</label><small class="label label-primary"><i class="fa fa-flag"></i> ' + comment["remarks"] + '</small> </div></li>'
                            }
                            else {
                                html += '<li id="username' + comment["id"] + '"> <div class="radio i-checks"> <label> <input type="radio" name="user-rad" value="' + comment["id"] + '"> <i></i> ' + comment["user_name"] + '</label><small class="label label-default"><i class="fa fa-user"></i> ' + comment["remarks"] + '</small> </div></li>'
                            }
                        });
                        $('#member-list').html(html);
                        $('#add-user-btn').removeAttr("disabled");
                    }
                }
            });
        }

        function task_list(id) {
            project_id = id;
            $.ajax({
                type: "POST",
                url: localhost + "/task/projectTaskList",
                data: '{"object_id":' + id + ',"page":1,"size":500}',
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        $('#task-list').empty();
                        var html = '';
                        $.each(data["response_data"]["data"], function (commentIndex, comment) {
                            leader_id = comment["id"];
                            comment["start_date"] = comment["start_date"].substring(0, 10)
                            if (comment["end_date"] == null) {
                                comment["end_date"] = "~";
                            }
                            else {
                                comment["end_date"] = comment["end_date"].substring(0, 10)
                            }
                            if(comment["status"]==0){
                                html += '<li> <div class="radio i-checks"><i class="fa fa-hourglass-1"></i> <label> <i></i> <h5>' + comment["content"] + '</h5></label><small class="label label-primary"> ' + comment["leader"] + '</small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["start_date"] + '</small> <small class="label ">=></small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["end_date"] + '</small> <button class="btn btn-sm btn-primary pull-right m-t-n-xs" onclick="member_list(' + comment["id"] + ')"><strong>成员</strong> </button> </div> </li>'

                            }else if(comment["status"]==1){
                                html += '<li> <div class="radio i-checks"><i class="fa fa-hourglass-2"></i> <label> <i></i> <h5>' + comment["content"] + '</h5></label><small class="label label-primary"> ' + comment["leader"] + '</small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["start_date"] + '</small> <small class="label ">=></small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["end_date"] + '</small> <button class="btn btn-sm btn-primary pull-right m-t-n-xs" onclick="member_list(' + comment["id"] + ')"><strong>成员</strong> </button> </div> </li>'

                            }else if(comment["status"]==3){
                                html += '<li> <div class="radio i-checks"><i class="fa fa-hourglass-3"></i> <label> <i></i> <h5>' + comment["content"] + '</h5></label><small class="label label-primary"> ' + comment["leader"] + '</small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["start_date"] + '</small> <small class="label ">=></small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["end_date"] + '</small></div> </li>'

                            }else{
                                html += '<li> <div class="radio i-checks"><i class="fa fa-hourglass-o"></i> <label> <i></i> <h5>' + comment["content"] + '</h5></label><small class="label label-primary"> ' + comment["leader"] + '</small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["start_date"] + '</small> <small class="label ">=></small> <small class="label "><i class="fa fa-clock-o"></i> ' + comment["end_date"] + '</small></div> </li>'
                            }
                        });
                        $('#task-list').html(html);
                    }
                }
            });
        }

        function detail_list() {
            $.ajax({
                type: "POST",
                url: localhost + "/project/projectInfoPerson",
                data: '{ "session_user_id": 1 }', //暂时测试,正式需要将其改为null
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json",
                success: function (data) {
                    if (data["response_msg"] == "success") {
                        $('#detail-ibox').empty();
                        var html = '';
                        $.each(data["response_data"], function (commentIndex, comment) {
                            html += ' <div class="ibox-content">';
                            if (comment["create_date"] != null) {
                                comment["create_date"] = comment["create_date"].substring(0, 10);
                            }
                            if (comment["plane_time"] != null) {
                                comment["plane_time"] = comment["plane_time"].substring(0, 10);
                            }
                            if (comment["end_date"] != null) {
                                comment["end_date"] = comment["end_date"].substring(0, 10);
                            }
                            if (comment["status"] == 0) {
                                html += '<div class="row"> <div class="col-sm-12"> <div class="m-b-md"><h2>' + comment["name"] + '</h2> </div> <dl class="dl-horizontal"> <dt>状态：</dt> <dd><span class="label label-primary" id="status-dd">准备中</span> </dd> </dl> </div> </div>';
                            } else if (comment["status"] == 1) {
                                html += '<div class="row"> <div class="col-sm-12"> <div class="m-b-md"><h2>' + comment["name"] + '</h2> </div> <dl class="dl-horizontal"> <dt>状态：</dt> <dd><span class="label label-primary" id="status-dd">进行中</span> </dd> </dl> </div> </div>';
                            } else if (comment["status"] == 2) {
                                html += '<div class="row"> <div class="col-sm-12"> <div class="m-b-md"><h2>' + comment["name"] + '</h2> </div> <dl class="dl-horizontal"> <dt>状态：</dt> <dd><span class="label label-primary" id="status-dd">暂停中</span> </dd> </dl> </div> </div>';
                            }
                            html += '<div class="row"> <div class="col-sm-5"> <dl class="dl-horizontal">'
                            html += '<dt>负责人：</dt> <dd>' + comment["leader"] + '</dd>';
                            html += '<dt>备注：</dt> <dd>' + comment["remarks"] + '</dd> <dt>任务：</dt> <dd><button class="btn btn-white btn-sm" onclick="task_list(' + comment['id'] + ')"><i class="fa fa-clock-o"></i> 查看</button></dd> ';
                            html += "</dl> </div>";

                            html += '<div class="col-sm-7" id="cluster_info"> <dl class="dl-horizontal">';
                            html += '<dt>创建日期：</dt> <dd id="creat-time-dd">' + comment["create_date"] + '</dd>'
                            html += '<dt>计划日期：</dt> <dd id="creat-time-dd">' + comment["plane_time"] + '</dd>'
                            html += '<dt>结束日期：</dt> <dd id="creat-time-dd">' + comment["end_date"] + '</dd>'
                            html += '</dl></div>';
                        });
                        $('#detail-ibox').html(html);
                    }
                }
            });
        }

        $(document).ready(function () {

            $('#loading-example-btn').click(function () {
                btn = $(this);
                simpleLoad(btn, true)

                // Ajax example
                //                $.ajax().always(function () {
                //                    simpleLoad($(this), false)
                //                });

                simpleLoad(btn, false)
            });
            detail_list();
        });

        function simpleLoad(btn, state) {
            if (state) {
                btn.children().addClass('fa-spin');
                btn.contents().last().replaceWith(" Loading");
            } else {
                setTimeout(function () {
                    btn.children().removeClass('fa-spin');
                    btn.contents().last().replaceWith(" Refresh");
                }, 2000);
            }
        }
    </script>




</body>

</html>